package com.gc.frontend.service.impl;

import com.gc.common.entity.Setting;
import com.gc.common.mapper.SettingMapper;
import com.gc.frontend.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 瑱彬 on 2015/4/30.
 */
@Service
public class SettingServiceImpl implements SettingService {
    @Autowired
    private SettingMapper settingMapper;

    @Override
    public int insert(Setting setting) {
        return this.settingMapper.insert(setting);
    }

    @Override
    public Setting get(String name) {
        return this.settingMapper.selectByName(name);
    }

    @Override
    public List<Setting> getAll() {
        return this.settingMapper.selectAll();
    }

    @Override
    public int update(Setting setting) {
        return this.settingMapper.updateByName(setting.getSettingName(), setting.getSettingValue());
    }

    @Override
    public Map<String, String> getMaps() {
        Map<String, String> maps = new HashMap<>();
        List<Setting> settings = this.getAll();
        for (Setting setting : settings) {
            maps.put(setting.getSettingName(), setting.getSettingValue());
        }
        return maps;
    }
}
